package com.xiaolun;

/**
 * @Author 硕鼠
 * @Date 2020/5/7 20:49
 * @Version 1.0
 * @Description 多个线程操作同一个对象
 */
public class Test04 implements Runnable{
    //票数
    private int tickNum = 10;

    @Override
    public void run() {
        while (true){
            if (tickNum <= 0){
                break;
            }

            //模拟延时
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "拿了第"+(tickNum--)+"票");
        }
    }

    public static void main(String[] args) {
        Test04 ticket = new Test04();

        new Thread(ticket, "小明").start();
        new Thread(ticket, "老师").start();
        new Thread(ticket, "黄牛党").start();
    }
}
